unit UMAIN;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, AdvToolBar, AdvGlowButton, AdvOfficePager,
  AdvOfficeStatusBar, StdCtrls, ComCtrls, AdvListV, AdvEdit, AdvGroupBox,
  ExtCtrls, AdvPanel;

type
  TFMAIN = class(TForm)
    AdvDockPanel1: TAdvDockPanel;
    AdvToolBar1: TAdvToolBar;
    AdvGlowButton1: TAdvGlowButton;
    AdvToolBarSeparator1: TAdvToolBarSeparator;
    AdvGlowButton2: TAdvGlowButton;
    AdvGlowButton3: TAdvGlowButton;
    AdvToolBarSeparator2: TAdvToolBarSeparator;
    AdvGlowButton4: TAdvGlowButton;
    AdvOfficeStatusBar1: TAdvOfficeStatusBar;
    AdvPanel1: TAdvPanel;
    AdvGroupBox1: TAdvGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    AdvGroupBox2: TAdvGroupBox;
    Label5: TLabel;
    Label6: TLabel;
    AdvGroupBox3: TAdvGroupBox;
    Label7: TLabel;
    Label8: TLabel;
    AdvGroupBox4: TAdvGroupBox;
    ed_v1: TEdit;
    ed_v2: TEdit;
    ed_v3: TEdit;
    ed_v4: TEdit;
    ed_nombre: TEdit;
    ed_cs_x: TAdvEdit;
    ed_cs_y: TAdvEdit;
    ed_pt_y: TAdvEdit;
    ed_pt_x: TAdvEdit;
    AdvOfficePager1: TAdvOfficePager;
    AdvOfficePager11: TAdvOfficePage;
    AdvOfficePager12: TAdvOfficePage;
    MEMO_OUT: TMemo;
    AdvListView1: TAdvListView;
    AdvGlowButton5: TAdvGlowButton;
    AdvGlowButton6: TAdvGlowButton;
    OPD1: TOpenDialog;
    SD1: TSaveDialog;
    OPD2: TOpenDialog;
    procedure FormShow(Sender: TObject);
    procedure AdvGlowButton5Click(Sender: TObject);
    procedure AdvGlowButton1Click(Sender: TObject);
    procedure AdvGlowButton2Click(Sender: TObject);
    procedure AdvGlowButton3Click(Sender: TObject);
    procedure AdvGlowButton4Click(Sender: TObject);
    procedure AdvGlowButton6Click(Sender: TObject);
  private
    { Private declarations }
  public
    Procedure PonDatos;
    Procedure CogeDatos;
  end;

var
  FMAIN: TFMAIN;

implementation

uses UDM;

{$R *.dfm}

procedure TFMAIN.AdvGlowButton1Click(Sender: TObject);
begin
//
CogeDatos;
if SD1.Execute then dm.SaveXML(SD1.FileName);
end;

procedure TFMAIN.AdvGlowButton2Click(Sender: TObject);
begin
if OPD1.Execute then
  if fileexists(opd1.FileName) then
    begin
    dm.LoadXML(OPD1.FileName);
    PonDatos;
    AdvGlowButton5Click(self);
    end;
end;

procedure TFMAIN.AdvGlowButton3Click(Sender: TObject);
begin
close;
end;

procedure TFMAIN.AdvGlowButton4Click(Sender: TObject);
begin
with DM.DATOS do
  begin
  v1:='V1';
  v2:='V2';
  v3:='V3';
  v4:='V4';
  NOMBRE:='Pertenencia';
  CS_X:=1000;
  CS_Y:=1000;
  PT_X:=500;
  PT_Y:=200;
  end;
PonDatos;
//
AdvListView1.Clear;
MEMO_OUT.Clear;
end;

procedure TFMAIN.AdvGlowButton5Click(Sender: TObject);
var
total:integer;
i: integer;
texto: string;
begin
CogeDatos;
DM.Calcula;
total:=Length(dm.SALIDA);
//
AdvListView1.Items.Clear;
MEMO_OUT.Clear;
texto:='';
//
for I := 0 to total - 1 do
  begin
  // LA REJILLA
  with AdvListView1.Items.Add do
    begin
    Caption:=DM.SALIDA[i].nombre;
    SubItems.Add(DM.SALIDA[i].V1);
    SubItems.Add(DM.SALIDA[i].V2);
    SubItems.Add(DM.SALIDA[i].V3);
    SubItems.Add(DM.SALIDA[i].V4);
    end;
  // EL TEXTO
  texto:=texto+(DM.SALIDA[i].Texto);
  end;
  MEMO_OUT.Text:=texto;
end;

procedure TFMAIN.AdvGlowButton6Click(Sender: TObject);
begin
CogeDatos;
AdvGlowButton5Click(self);
if OPD2.Execute then MEMO_OUT.Lines.SaveToFile(OPD2.FileName);

end;

procedure TFMAIN.CogeDatos;
begin
DM.datos.v1:=ed_v1.Text;
DM.datos.v2:=ed_v2.Text;
DM.datos.v3:=ed_v3.Text;
DM.datos.v4:=ed_v4.Text;

DM.datos.NOMBRE:=ed_nombre.Text;

DM.datos.CS_X:=ed_cs_x.FloatValue;
DM.datos.CS_Y:=ed_cs_y.FloatValue;
DM.datos.PT_X:=ed_pt_x.FloatValue;
DM.datos.PT_Y:=ed_pt_y.FloatValue;
end;

procedure TFMAIN.FormShow(Sender: TObject);
begin
PonDatos;
AdvOfficePager1.ActivePageIndex:=0;
end;


procedure TFMAIN.PonDatos;
begin
ed_v1.Text:=          DM.datos.v1;
ed_v2.Text:=          DM.datos.v2;
ed_v3.Text:=          DM.datos.v3;
ed_v4.Text:=          DM.datos.v4;

ed_nombre.Text:=      DM.datos.NOMBRE;

ed_cs_x.FloatValue:=  DM.datos.CS_X;
ed_cs_y.FloatValue:=  DM.datos.CS_Y;
ed_pt_x.FloatValue:=  DM.datos.PT_X;
ed_pt_y.FloatValue:=  DM.datos.PT_Y;
end;

end.
